﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.OMM.HealthMonitor.Collector.SharedHealthDataMemoryStorage.Receiver;
using Sinacor.OMM.HealthMonitor.Entity.Receiver;
using Sinacor.OMM.HealthMonitor.Collector;
using Sinacor.OMM.HealthMonitor.Configuration;

namespace Sinacor.OMM.HealthMonitor.Server.Controller
{
    public class HsCtrlReceiverShdms
    {

        public static ReceiverData CheckExpiration(ReceiverData receiverData)
        {
            ReceiverData ret = null;

            if (receiverData != null)
            {
                int secondsToExpire = OMM.HealthMonitor.Configuration.HealthMonitorConfigurationManager.HealthMonitorConfiguration.TimeToRefreshMonitorSeconds * 5;
                
                double timeElaspseSinceLastUpdate = DateTime.Now.Subtract(receiverData.LastUpdate).TotalSeconds;

                if (timeElaspseSinceLastUpdate >= secondsToExpire)
                    ret = null;
                else
                    ret = receiverData;
            }

            return ret;
        }
    }
}
